package com.droidclaimcustomer.bl;

import java.lang.reflect.Type;
import java.text.DateFormat;
import java.util.Date;

import com.droidclaimcustomer.dto.CustomerBlDto;
import com.droidclaimcustomer.helper.service.DateDeserializer;
import com.droidclaimcustomer.helper.service.RestfulWebService;
import com.droidclaimcustomer.helper.service.ServiceMethod;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;

//
// Service Method :
// public List<CustomerDto> GetAllCustomer()
//
public class GetAllCustomerMethod extends ServiceMethod<CustomerBlDto>{
	public static String METHOD_NAME = "GetCustomer";
	private Gson gson;
	
	public GetAllCustomerMethod(){
		 gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateDeserializer())
				 		.serializeNulls()
				 		.setDateFormat(DateFormat.LONG)
				 		.setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)
				 		.setPrettyPrinting()
				 		.create();
	}
	
	
	@Override
	public String getName() {
		return GetAllCustomerMethod.METHOD_NAME;
	}

	@Override
	public String getParameter() {
		String result = "";
		/*
		result = gson.toJson(parmeterObject);
		*/
		
		/*List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("param1","value1"));
		result = '?' + URLEncodedUtils.format(params, "utf-8");
		*/
		
		return result;
	}
	
	@Override
	public int getMethodType(){
		return RestfulWebService.HTTP_GET;
	}
	
	public CustomerBlDto mapResponse(String json){
		if(json.isEmpty()){
			return new CustomerBlDto();
		}
		
		Type listType = new TypeToken<CustomerBlDto>(){}.getType();
		CustomerBlDto result = gson.fromJson(json, listType);
		
		return result;
	}
}
